<template>
  <div class="box-main" v-if="!showDetail">
    <div class="topHeaderCard">
      <a-button type="primary" @click="resetBack" :icon="h(ArrowLeftOutlined)" ghost>
        返回
      </a-button>
    </div>
    <div class="box-main-content">
      <div class="page-content">
        <div style="width: 100%; height: 120px; padding: 24px 24px 0; background-color: #fff">
          <div class="info-header">
            <div class="info-left">
              <div class="patient-info">
                <img
                  :src="
                    memberInfo && memberInfo.gender
                      ? memberInfo.gender == '男性'
                        ? manPic
                        : womanPic
                      : userPic
                  "
                  alt=""
                />
                <div class="patient-right">
                  <div style="display: flex; align-items: center">
                    <div style="display: flex; align-items: center">
                      <span style="font-size: 20px; font-weight: 600; color: rgb(29, 33, 41)">
                        {{ memberInfo ? memberInfo.patName : '' }}
                      </span>
                      <span style="margin: 0 12px; color: #4e5969">{{
                        memberInfo ? (memberInfo.age ? memberInfo.age + '岁' : '') : ''
                      }}</span>
                      <span style="color: #4e5969"> {{ memberInfo ? memberInfo.gender : '' }}</span>
                    </div>

                    <div class="visit-info" style="margin: 0 48px">
                      报告生成时间：<span style="color: #1d2129">{{
                        memberInfo ? memberInfo.visitTime : ''
                      }}</span>
                    </div>
                    <div class="member-info">
                      会员有效期：
                      <span style="color: #1d2129">
                        {{
                          memberInfo && memberInfo.buyTime
                            ? dayjs(memberInfo.buyTime).format('YYYY-MM-DD HH:mm')
                            : ''
                        }}
                      </span>
                      <span style="color: #1d2129">
                        ~
                        {{
                          memberInfo && memberInfo.expiredTime
                            ? dayjs(memberInfo.expiredTime).format('YYYY-MM-DD HH:mm')
                            : ''
                        }}
                      </span>
                    </div>
                  </div>
                  <span style="color: #4e5969"
                    >联系电话：
                    <span style="color: #1d2129">{{
                      memberInfo ? memberInfo.phone : ''
                    }}</span></span
                  >
                </div>
              </div>
            </div>
            <div class="info-right">
              <a-button type="primary" ghost @click="goPatientDetail"> 患者详情</a-button>
            </div>
          </div>
        </div>
        <div class="info-content">
          <template v-if="!isQuestionState">
            <div class="empty-box">
              <a-empty :image-style="{ height: '119px' }">
                <template #image>
                  <div>
                    <img
                      style="width: 208px; height: 119px"
                      src="@/assets/health/noQuestion.png"
                      alt=""
                    />
                  </div>
                </template>
                <template #description>
                  <div style="margin: 16px 0; font-size: 16px; color: #1d2129">
                    患者还没有完成评估问卷，请联系用户填写问卷
                  </div>
                  <div>
                    <a-button type="primary" @click="goIM">联系患者</a-button>
                  </div>
                </template>
              </a-empty>
            </div>
          </template>
          <template v-else>
            <div class="mana-plan-box">
              <div style="display: flex; justify-content: space-between">
                <div class="mana-plan-title">
                  <span class="text-icon" v-if="memberInfo && memberInfo.pathName" />
                  <span>{{ memberInfoPath }}</span>

                  <a-button type="link" :disabled="isPushed" @click="changePath">
                    <template #icon>
                      <img
                        style="width: 16px; height: 16px; margin-right: 8px"
                        src="@/assets/health/path-icon.png"
                        alt=""
                      />
                    </template>
                    切换路径
                  </a-button>
                </div>
                <a-button type="primary" style="margin-right: 8px" @click="planPushPlanHisHandle"
                  >方案执行情况</a-button
                >
              </div>
              <div class="mana-plan-content">
                <div class="mana-plan-content-info">
                  <div class="mana-plan-item">
                    <a-tabs v-model:activeKey="manaItemIndex" type="card">
                      <a-tab-pane v-for="(item, index) in manaItemList" :key="index" :tab="item" />
                    </a-tabs>
                  </div>
                  <div class="mana-plan-main">
                    <template v-if="manaItemList[manaItemIndex] === '健康处方'">
                      <Health
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:prescriptionData="manaPlanForm.prescriptionData"
                        :empi="memberInfo.empi"
                        :diseaseType="diseaseType"
                        :startTime="historyPathStartTime"
                        :expiredTime="expiredTime"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '饮食方案'">
                      <Diet
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:dietData="manaPlanForm.dietData"
                        :empi="memberInfo.empi"
                        :diseaseType="diseaseType"
                        :serviceState="memberInfo.serviceState"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '运动方案'">
                      <Sports
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:sportData="manaPlanForm.sportData"
                        :empi="memberInfo.empi"
                        :diseaseType="diseaseType"
                        :serviceState="memberInfo.serviceState"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '健康宣教'">
                      <Education
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:propagandaData="manaPlanForm.propagandaData"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '健康随访'">
                      <Follow
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:followData="manaPlanForm.followData"
                        :startTime="historyPathStartTime"
                        :expiredTime="expiredTime"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '健康监测'">
                      <Monitor
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:monitorData="manaPlanForm.monitorData"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '用药提醒'">
                      <Medication
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:medicationData="manaPlanForm.medicationData"
                      />
                    </template>
                    <template v-else-if="manaItemList[manaItemIndex] === '就诊提醒'">
                      <Remind
                        :isPushed="isPushed || memberInfo.memberState != '生效中'"
                        v-model:visitData="manaPlanForm.visitData"
                        :startTime="historyPathStartTime"
                        :expiredTime="expiredTime"
                      />
                    </template>
                  </div>
                </div>
                <div class="mana-plan-footer">
                  <template v-if="memberInfo.memberState == '生效中'">
                    <a-space>
                      <template v-if="!isPushed">
                        <a-button html-type="submit" @click="staging">暂存</a-button>
                        <a-button type="primary" @click="createPlan">生成方案</a-button>
                      </template>
                      <template v-else>
                        <a-button type="primary" @click="isPushed = false">修改方案</a-button>
                      </template>
                    </a-space>
                  </template>
                </div>
              </div>
            </div>
          </template>
        </div>
      </div>
    </div>
    <!-- 推送方案确认框 -->
    <a-modal
      v-model:open="isPushPlan"
      title=""
      :closable="false"
      :footer="null"
      :maskClosable="false"
    >
      <a-spin :spinning="isCreateHealthInfo">
        <div style="padding-top: 16px">
          <a-empty :image-style="{ height: '110px' }">
            <template #image>
              <div>
                <img
                  style="width: 162px; height: 110px"
                  src="@/assets/health/plan-image.png"
                  alt=""
                />
              </div>
            </template>
            <template #description>
              <div style="margin: 24px 0; font-size: 16px; color: #1d2129; text-align: left">
                <span v-if="isCreatePlan">
                  已调整患者的健康管理方案，新的健康任务将于明天开始实施。是否确定向患者推送该方案？
                </span>
                <span v-else
                  >已为患者制定健康管理方案，健康任务将于明天开始正式提醒，是否确认向患者推送该方案？</span
                >
                <!-- 已为患者{{ isCreatePlan ? '修改' : '生成' }}健康管理方案，{{
                  isCreatePlan ? '修改后的' : ''
                }}健康任务将在明天开始{{
                  isCreatePlan ? '调整' : '正式提醒'
                }}，是否确定向患者推送方案吗？ -->
              </div>
              <div>
                <a-space>
                  <a-button @click="isPushPlan = false">暂不推送</a-button>
                  <a-button type="primary" @click="pushPlanBtn" v-if="!isCreatePlan">
                    审核无误，确认推送
                  </a-button>
                  <a-button type="primary" @click="pushPlanBtn" v-else>确认推送</a-button>
                </a-space>
              </div>
            </template>
          </a-empty>
        </div>
      </a-spin>
    </a-modal>
    <!-- 方案执行情况 -->
    <!-- <PlanPushPlan ref="planPushPlanRef" @goPage="goPage"></PlanPushPlan> -->
    <planPushPlanHis ref="planPushPlanHisRef" @goPage="goPage" @refreshData="refreshData" />
    <!-- 切换路径 -->
    <a-modal v-model:open="pathOpen" title="切换路径" :maskClosable="false">
      <a-form ref="pathForm" :model="pathFormData">
        <a-form-item label="系统匹配路径">{{ changePathName }}</a-form-item>
        <a-form-item label="当前执行路径">{{ memberInfo.executePathName }}</a-form-item>
        <a-form-item
          name="pathId"
          label="切换新路径"
          :rules="[{ required: true, message: '请选择路径' }]"
        >
          <a-select
            :options="pathDataList"
            v-model:value="pathFormData.pathId"
            placeholder="请选择路径"
            style="width: 100%"
            show-search
          />
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button @click="pathOpen = false">取消</a-button>
        <a-button type="primary" @click="savePath">确定</a-button>
      </template>
    </a-modal>
  </div>
  <PatientInfo ref="patientInfoRef" v-else @close="goBack" />
</template>
<script setup lang="ts">
import manPic from '@/assets/patient/man.png'
import womanPic from '@/assets/patient/woman.png'
import userPic from '@/assets/user.png'
import { ref, reactive, onMounted, h } from 'vue'
import { ArrowLeftOutlined, LeftOutlined } from '@ant-design/icons-vue'
import {
  getMemberInfo,
  getTemplateDetailList,
  getManagePathDetail,
  holdManagePath,
  generateManagePath,
  reMatchManagePath,
  getAllManagePath,
  getHistoryPath,
  getSchemeFirstPushTime,
  getAiCycleTask
} from '@/api/healthManaWorkbench'
import { manageInfo } from '@/api/manage'
import { getTags } from '@/api/template.ts'
import message from 'ant-design-vue/es/message'

import planPushPlanHis from './planPushPlanHis.vue'
import PatientInfo from '@/views/examinatePatients/patientInfo.vue'
import { useRouter } from 'vue-router'
import store from '@/store'
import Health from './manaPlan/Health.vue'
import Diet from './manaPlan/Diet.vue'
import Sports from './manaPlan/Sports.vue'
import Education from './manaPlan/Education.vue'
import Follow from './manaPlan/Follow.vue'
import Monitor from './manaPlan/Monitor.vue'
import Medication from './manaPlan/Medication.vue'
import Remind from './manaPlan/Remind.vue'
import _ from 'lodash'
import { throttle } from '@/utils/tools'
import dayjs from 'dayjs'

const isCreateHealthInfo = ref(false)
const router = useRouter()

const manaItemList = ref([])

const manaPlanTabData = reactive([
  {
    label: '健康处方',
    key: 'health'
  },
  {
    label: '饮食方案',
    key: 'diet'
  },
  {
    label: '运动方案',
    key: 'sports'
  },
  {
    label: '健康宣教',
    key: 'education'
  },
  {
    label: '健康随访',
    key: 'follow'
  },
  {
    label: '健康监测',
    key: 'monitor'
  },
  {
    label: '用药提醒',
    key: 'medication'
  },
  {
    label: '就诊提醒',
    key: 'remind'
  }
])
const manaItemIndex = ref(-1)
const currentManaItemIndex = ref(0)
// const dietActiveKey = ref(0)
const emit = defineEmits(['close'])

const showDetail = ref(false)

const isQuestionState = ref(false)
const isPushed = ref(false)
const initPushState = ref(false)

const individualTemplateList = ref([])

const propagandaLabelsData = ref([])

// 路径
const pathOpen = ref<boolean>(false)
const pathFormData = reactive({
  pathId: undefined
})
const pathDataList = ref([])

const changePath = () => {
  pathOpen.value = true
  pathDataList.value = []
  nextTick(() => {
    if (pathForm.value) {
      pathForm.value.resetFields()
    }

    getAllManagePath({ diseaseType: diseaseType.value }).then((res) => {
      res.data.map((item) => {
        item.value = item.id
        item.label = item.managePathName
      })
      pathDataList.value = res.data
    })
  })
}

const changePathName = ref('')
const pathForm = ref()
const savePath = () => {
  pathForm.value.validate().then((res) => {
    // const newPath = pathDataList.value.filter(item => {
    //   return item.id == pathFormData.pathId
    // })

    manageInfo(pathFormData.pathId).then(async (res) => {
      message.success('切换成功')
      manaPlanForm.prescriptionData = []
      manaPlanForm.dietData = []
      manaPlanForm.sportData = []
      manaPlanForm.propagandaData = []
      manaPlanForm.followData = []
      manaPlanForm.monitorData = []
      manaPlanForm.medicationData = []
      manaPlanForm.visitData = []
      pathOpen.value = false
      // memberInfo.value.pathName = res.data.managePathName
      memberInfoPath.value = res.data.managePathName
      memberInfo.value.executePathId = res.data.id
      const pathManageTemplateVOList = res.data.pathManageTemplateVOList

      pathManageTemplateVOList.forEach(async (item, index) => {
        const templateType = item.templateType
        item.oldTemeplateId = item.templateId
        item.oldTemplateAffiliation = item.templateAffiliation
        item.templateList = templateDataList.value.filter((tem) => {
          return (
            tem.templateType == templateType && tem.templateAffiliation == item.templateAffiliation
          )
        })

        const startDate = dayjs(historyPathStartTime.value)

        switch (templateType) {
          case '健康处方':
            item.aiStatus = 0
            item.aiCodeLabel = '可通过AI大模型为用户生成健康处方'
            item.sendTime = item.cronCycle ? startDate.add(item.cronCycle, 'day') : ''
            item.cronCycleInit = item.cronCycle
            manaPlanForm.prescriptionData.push(item)
            break
          case '饮食方案':
            if (item.templateAffiliation === '个人模板') {
              // 如果是个人模板时 当前个人模板不在列表中 需要在选择模板下拉中加入当前的模板数据
              item.personTempId = item.templateId
              item.personTempName = item.templateName
              item.personTempContent = item.content

              item.templateList.findIndex((ele) => {
                return ele.templateId == item.personTempId
              }) === -1 &&
                item.templateList.push({
                  templateId: item.personTempId,
                  templateName: item.personTempName,
                  content: item.personTempContent,
                  templateType: '饮食方案',
                  templateAffiliation: '个人模板',
                  creator: userId.value,
                  label: item.templateName,
                  value: item.personTempId,
                  id: item.personTempId
                })
            }
            item.aiStatus = 40
            item.aiCodeLabel = '可通过AI大模型为用户生成饮食方案'
            item.cycleStart = null
            item.onShowTask = true
            item.pushStatus = null
            item.activeKey = 0
            if (item.content) {
              const contentDiet = JSON.parse(item.content)
              item.content = contentDiet
            }
            if (item.templateAffiliation == 'AI生成') {
              manaPlanForm.dietData.push({ ...item, ...(await getAiTask('DIET')) })
            } else {
              manaPlanForm.dietData.push(item)
            }
            break
          case '运动方案':
            if (item.templateAffiliation === '个人模板') {
              // 如果是个人模板时 当前个人模板不在列表中 需要在选择模板下拉中加入当前的模板数据
              item.personTempId = item.templateId
              item.personTempContent = item.content
              item.personTempName = item.templateName

              item.templateList.findIndex((ele) => {
                return ele.templateId == item.personTempId
              }) === -1 &&
                item.templateList.push({
                  templateId: item.personTempId,
                  templateName: item.personTempName,
                  content: item.personTempContent,
                  templateType: '运动方案',
                  templateAffiliation: '个人模板',
                  creator: userId.value,
                  label: item.templateName,
                  value: item.personTempId,
                  id: item.personTempId
                })
            }
            item.aiStatus = 0
            item.aiCodeLabel = '可通过AI大模型为用户生成运动方案'

            item.cycleStart = null
            item.onShowTask = true
            item.pushStatus = null
            item.activeKey = 0
            if (item.content) {
              const contentDiet = JSON.parse(item.content)
              item.content = contentDiet
            }
            if (item.templateAffiliation == 'AI生成') {
              manaPlanForm.sportData.push({ ...item, ...(await getAiTask('SPORT')) })
            } else {
              manaPlanForm.sportData.push(item)
            }

            break
          case '健康宣教':
            if (typeof item.content === 'string' && item.content.trim().startsWith('[')) {
              item.contents = JSON.parse(item.content)
            } else {
              item.contents = [item.content]
            }

            manaPlanForm.propagandaData.push(item)
            break
          case '健康随访':
            item.cronCycleInit = item.cronCycle
            item.sendTime = item.cronCycle ? startDate.add(item.cronCycle, 'day') : ''
            manaPlanForm.followData.push(item)
            break
          case '健康监测':
            item.contents = {
              // content: '',
              sings: undefined
            }
            if (typeof item.content === 'string') {
              try {
                const dataString = JSON.parse(item.content)
                if (typeof dataString === 'object') {
                  item.contents = {
                    // content: dataString.content ? dataString.content : '',
                    sings: dataString.sings ? dataString.sings : undefined
                  }
                } else {
                  item.contents = {
                    // content: item.content,
                    sings: undefined
                  }
                }
                item.cronDates = dataString.cronDate ? dataString.cronDate.split(',') : []
                const cronTimes = dataString.cronTime ? dataString.cronTime.split(',') : []
                item.cronTimes = cronTimes
              } catch (e) {
                item.contents = {
                  // content: item.content,
                  sings: undefined
                }
              }
            }
            // cronTimes.forEach((ele, index) => {
            //   item.cronTimes.push(dayjs(ele, 'HH:mm'))
            // })
            manaPlanForm.monitorData.push(item)
            break
          case '用药提醒':
            item.cronDates = item.cronDate ? item.cronDate.split(',') : []
            item.cronTimes = item.cronTime ? item.cronTime.split(',') : []
            // cronTimes1.forEach((ele, index) => {
            //   item.cronTimes.push(dayjs(ele, 'HH:mm'))
            // })
            manaPlanForm.medicationData.push(item)
            break
          case '就诊提醒':
            item.cronCycleInit = item.cronCycle
            item.sendTime = item.cronCycle ? startDate.add(item.cronCycle, 'day') : ''
            manaPlanForm.visitData.push(item)
            break
          default:
            break
        }
      })

      manaItemIndex.value = -1
      setTimeout(() => {
        manaItemIndex.value = currentManaItemIndex.value
      }, 100)
    })
  })
}

// 模板

const memberInfo = ref()
const patientInfoRef = ref()
const isCreatEdPdf = ref(false)
let pathManageTemplateData: any = undefined // 原始方案
// 患者详情跳转
const goPatientDetail = () => {
  showDetail.value = true
  nextTick(() => {
    patientInfoRef.value.init({
      empi: memberInfo.value.empi
    })
  })
}

interface ManaPlanForm {
  prescriptionData: any[]
  dietData: any[]
  sportData: any[]
  propagandaData: any[]
  followData: any[]
  monitorData: any[]
  medicationData: any[]
  visitData: any[]
}

const manaPlanForm = reactive<ManaPlanForm>({
  prescriptionData: [],
  dietData: [],
  sportData: [],
  propagandaData: [],
  followData: [],
  monitorData: [],
  medicationData: [],
  visitData: []
})

const memberRouterData: any = ref()

const templateDataList = ref([])

const userId = ref()

const isCreatePlan = ref(false)

// const dietDictData = ref([])
// const sportDictData = ref([])

const memberInfoPath = ref('') // 当前路径名称
const diseaseType = ref<any>()

const historyPathStartTime = ref()
const historyPathData = ref()

const expiredTime = ref()
const init = async (data, disType?: any) => {
  // console.log(data)
  manaItemIndex.value = -1
  setTimeout(() => {
    if (data.noticeTag) {
      switch (data.noticeTag) {
        case 'DIET_PLAN_WAIT_REVIEW':
          manaItemIndex.value = manaPlanTabData.findIndex((vo) => vo.key == 'diet')
          break
        case 'SPORT_PLAN_WAIT_REVIEW':
          manaItemIndex.value = manaPlanTabData.findIndex((vo) => vo.key == 'sports')
          break
        default:
          manaItemIndex.value = currentManaItemIndex.value
          break
      }
    } else {
      manaItemIndex.value = currentManaItemIndex.value
    }
  }, 100)
  await getManaPlanTabs()
  // console.log(JSON.stringify(store.userApp.permissionList))
  diseaseType.value = disType ? disType : 'checkAfter'
  isCreateHealthInfo.value = false
  isCreatEdPdf.value = false
  memberRouterData.value = data
  // executePathName.value = ''

  changePathName.value = ''
  memberInfoPath.value = ''

  manaPlanForm.prescriptionData = []
  manaPlanForm.dietData = []
  manaPlanForm.sportData = []
  manaPlanForm.propagandaData = []
  manaPlanForm.followData = []
  manaPlanForm.monitorData = []
  manaPlanForm.medicationData = []
  manaPlanForm.visitData = []

  userId.value = store.userApp.userInfo.id
  const param = 'empi=' + data.empi + '&diseaseType=' + diseaseType.value
  getHistoryPath(param).then((res) => {
    historyPathData.value = res.data
    if (res.data && res.data.length > 0) {
      isCreatePlan.value = true
    } else {
      isCreatePlan.value = false
    }
  })

  await getSchemeFirstPushTime(param).then((res) => {
    historyPathStartTime.value = dayjs(res.data).format('YYYY-MM-DD')
  })

  getTags().then((res) => {
    res.data.map((item) => {
      item.label = item.dictLabel
      item.value = item.dictLabel
    })
    propagandaLabelsData.value = res.data
  })

  templateDataList.value = await getTemplateList(null, null)

  getMemberInfo({
    empi: data.empi,
    userId: data.userId,
    diseaseType: diseaseType.value
  })
    .then((res) => {
      if (res.data) {
        memberInfo.value = res.data

        if (res.data.memberState != '生效中') {
          message.info('该用户的会员已失效！')
        }

        changePathName.value = res.data.pathName
        memberInfoPath.value = res.data.executePathName
          ? res.data.executePathName
          : res.data.pathName

        expiredTime.value = dayjs(res.data.expiredTime).format('YYYY-MM-DD')

        isQuestionState.value = res.data.questionState
        isPushed.value =
          initPushState.value && !isPushed.value
            ? false
            : res.data.serviceState == 'DONE'
              ? true
              : false
        initPushState.value = res.data.serviceState == 'DONE' ? true : false

        if (res.data.serviceState == 'TODO') {
          reMatchManagePath({
            empi: data.empi,
            diseaseType: diseaseType.value
          }).then((res) => {})
        }

        // if (res.data.pathId) {
        getManagePathDetail({
          pathId: memberInfo.value.pathId,
          empi: memberInfo.value.empi,
          userId: memberInfo.value.userId,
          diseaseType: diseaseType.value
        }).then(async (res) => {
          if (res.data) {
            const pathManageTemplateVOList = res.data

            // pathManageTemplateData = JSON.stringify(pathManageTemplateVOList)
            const datalist = JSON.parse(JSON.stringify(pathManageTemplateVOList))
            datalist.forEach((item) => {
              delete item.templateList
            })

            res.data.forEach(async (item, index) => {
              const templateType = item.templateType
              item.oldTemeplateId = item.templateId
              item.oldTemplateAffiliation = item.templateAffiliation
              if (item.templateAffiliation === '个人模板') {
                item.templateList = templateDataList.value.filter((tem) => {
                  return (
                    tem.templateType == templateType &&
                    tem.templateAffiliation == item.templateAffiliation &&
                    tem.creator == userId.value
                  )
                })
              } else {
                item.templateList = templateDataList.value.filter((tem) => {
                  return (
                    tem.templateType == templateType &&
                    tem.templateAffiliation == item.templateAffiliation
                  )
                })
              }

              const startDate = dayjs(historyPathStartTime.value)

              switch (templateType) {
                case '健康处方':
                  item.aiStatus = 0
                  item.aiCodeLabel = '可通过AI大模型为用户生成健康处方'
                  // item.startTime = startDate.add(item.cronCycle + 1, 'day')
                  item.sendTime = item.cronCycle ? startDate.add(item.cronCycle, 'day') : ''
                  item.cronCycleInit = item.cronCycle
                  manaPlanForm.prescriptionData.push(item)
                  break
                case '饮食方案':
                  if (item.templateAffiliation === '个人模板') {
                    // 如果是个人模板时 当前个人模板不在列表中 需要在选择模板下拉中加入当前的模板数据
                    item.personTempId = item.templateId
                    item.personTempName = item.templateName
                    item.personTempContent = item.content

                    item.templateList.findIndex((ele) => {
                      return ele.id == item.personTempId
                    }) === -1 &&
                      item.templateList.push({
                        templateId: item.personTempId,
                        templateName: item.personTempName,
                        content: item.personTempContent,
                        templateType: '饮食方案',
                        templateAffiliation: '个人模板',
                        creator: userId.value,
                        label: item.templateName,
                        value: item.personTempId,
                        id: item.personTempId
                      })
                  }
                  item.aiStatus = 40
                  item.aiCodeLabel = '可通过AI大模型为用户生成饮食方案'
                  item.cycleStart = null
                  item.onShowTask = true
                  item.pushStatus = null
                  item.activeKey = 0
                  if (item.content) {
                    const contentDiet = JSON.parse(item.content)
                    item.content = contentDiet
                  }

                  if (item.templateAffiliation == 'AI生成') {
                    manaPlanForm.dietData.push({ ...item, ...(await getAiTask('DIET')) })
                  } else {
                    manaPlanForm.dietData.push(item)
                  }

                  break
                case '运动方案':
                  if (item.templateAffiliation === '个人模板') {
                    // 如果是个人模板时 当前个人模板不在列表中 需要在选择模板下拉中加入当前的模板数据
                    item.personTempId = item.templateId
                    item.personTempContent = item.content
                    item.personTempName = item.templateName

                    item.templateList.findIndex((ele) => {
                      return ele.id == item.personTempId
                    }) === -1 &&
                      item.templateList.push({
                        templateId: item.personTempId,
                        templateName: item.personTempName,
                        content: item.personTempContent,
                        templateType: '运动方案',
                        templateAffiliation: '个人模板',
                        creator: userId.value,
                        label: item.templateName,
                        value: item.personTempId,
                        id: item.personTempId
                      })
                  }
                  item.aiStatus = 0
                  item.aiCodeLabel = '可通过AI大模型为用户生成运动方案'

                  item.cycleStart = null
                  item.onShowTask = true
                  item.pushStatus = null
                  item.activeKey = 0
                  if (item.content) {
                    const contentDiet = JSON.parse(item.content)
                    item.content = contentDiet
                  }

                  if (item.templateAffiliation == 'AI生成') {
                    manaPlanForm.sportData.push({ ...item, ...(await getAiTask('SPORT')) })
                  } else {
                    manaPlanForm.sportData.push(item)
                  }

                  break
                case '健康宣教':
                  if (typeof item.content === 'string' && item.content.trim().startsWith('[')) {
                    item.contents = JSON.parse(item.content)
                  } else {
                    item.contents = [item.content]
                  }

                  manaPlanForm.propagandaData.push(item)
                  break
                case '健康随访':
                  // item.startTime = startDate.add(item.cronCycle + 1, 'day')
                  item.cronCycleInit = item.cronCycle
                  item.sendTime = item.cronCycle ? startDate.add(item.cronCycle, 'day') : ''
                  manaPlanForm.followData.push(item)
                  break
                case '健康监测':
                  item.contents = {
                    // content: '',
                    sings: undefined
                  }
                  if (typeof item.content === 'string') {
                    try {
                      const dataString = JSON.parse(item.content)
                      if (typeof dataString === 'object') {
                        item.contents = {
                          // content: dataString.content ? dataString.content : '',
                          sings: dataString.sings ? dataString.sings : undefined
                        }
                      } else {
                        item.contents = {
                          // content: item.content,
                          sings: undefined
                        }
                      }
                      item.cronDates = dataString.cronDate ? dataString.cronDate.split(',') : []
                      const cronTimes = dataString.cronTime ? dataString.cronTime.split(',') : []
                      item.cronTimes = cronTimes
                    } catch (e) {
                      item.contents = {
                        // content: item.content,
                        sings: undefined
                      }
                    }
                  }
                  // cronTimes.forEach((ele, index) => {
                  //   item.cronTimes.push(dayjs(ele, 'HH:mm'))
                  // })
                  manaPlanForm.monitorData.push(item)
                  break
                case '用药提醒':
                  item.cronDates = item.cronDate ? item.cronDate.split(',') : []
                  item.cronTimes = item.cronTime ? item.cronTime.split(',') : []
                  // cronTimes1.forEach((ele, index) => {
                  //   item.cronTimes.push(dayjs(ele, 'HH:mm'))
                  // })
                  manaPlanForm.medicationData.push(item)
                  break
                case '就诊提醒':
                  // item.startTime = startDate.add(item.cronCycle + 1, 'day')
                  item.cronCycleInit = item.cronCycle
                  item.sendTime = item.cronCycle ? startDate.add(item.cronCycle, 'day') : ''
                  manaPlanForm.visitData.push(item)
                  break
                default:
                  break
              }
            })

            if (memberInfo.value.questionnaireRecordId) {
              const dietPlanDataIndex = res.data.findIndex(
                (vo: any) => vo.templateType === '饮食方案'
              )
              if (dietPlanDataIndex === -1) {
                const routeManaData: any = await getManagePathDetail({
                  pathId: memberInfo.value.pathId,
                  diseaseType: diseaseType.value
                })
                const dietRouteManaData = routeManaData.data.find(
                  (vo: any) => vo.templateType === '饮食方案'
                )
                if (dietRouteManaData) {
                  if (dietRouteManaData.content) {
                    const contentDiet = JSON.parse(dietRouteManaData.content)
                    dietRouteManaData.content = contentDiet
                  }
                  dietRouteManaData.templateList = templateDataList.value.filter((tem) => {
                    return tem.templateType == '饮食方案' && tem.templateAffiliation == '公共模板'
                  })
                  manaPlanForm.dietData.push(dietRouteManaData)
                }
              }
            } else {
              const dietIndex = datalist.findIndex((vo: any) => vo.templateType === '饮食方案')
              if (dietIndex !== -1) {
                datalist.splice(dietIndex, 1)
              }
            }

            if (memberInfo.value.questionnaireRecordId) {
              const sportPlanDataIndex = res.data.findIndex(
                (vo: any) => vo.templateType === '运动方案'
              )
              if (sportPlanDataIndex === -1) {
                const routeManaData: any = await getManagePathDetail({
                  pathId: memberInfo.value.pathId,
                  diseaseType: diseaseType.value
                })
                const sportRouteManaData = routeManaData.data.find(
                  (vo: any) => vo.templateType === '运动方案'
                )
                if (sportRouteManaData) {
                  if (sportRouteManaData.content) {
                    const contentDiet = JSON.parse(sportRouteManaData.content)
                    sportRouteManaData.content = contentDiet
                  }
                  sportRouteManaData.templateList = templateDataList.value.filter((tem) => {
                    return tem.templateType == '运动方案' && tem.templateAffiliation == '公共模板'
                  })
                  manaPlanForm.sportData.push(sportRouteManaData)
                }
              }
            } else {
              const sportIndex = datalist.findIndex((vo: any) => vo.templateType === '运动方案')
              if (sportIndex !== -1) {
                datalist.splice(sportIndex, 1)
              }
            }

            pathManageTemplateData = JSON.stringify(datalist)
            // console.log(manaPlanForm)
          }
        })
      } else {
        memberInfo.value = {}
        message.warning('暂无数据')
      }
    })
    .catch(() => {
      memberInfo.value = {}
    })

  if (data.templateType) {
    planPushPlanHisRef.value.initRouter(data)
  }
}

const getAiTask = async (type: any) => {
  const params = {
    empi: memberInfo.value.empi,
    planType: type
  }

  let aitaskList: any = {}
  await getAiCycleTask(params).then((res: any) => {
    if (res.data && res.data.length > 0) {
      res.data.forEach((item: any) => {
        const vo = {
          id: item.id,
          aiStatus: 40,
          AIContent: JSON.parse(item.modelContent),
          content: JSON.parse(item.modelContent),
          AITaskData: JSON.parse(item.modelContent),
          templateAffiliation: 'AI生成',
          cycleStart: dayjs(item.cycleStart).format('YYYY-MM-DD'),
          cycleEnd: dayjs(item.cycleEnd).format('YYYY-MM-DD'),
          pushStatus: item.pushStatus,
          aiCodeLabel: '',
          onShowTask: true,
          activeKey: 0,
          oldTemplateAffiliation: 'AI生成'
        }
        aitaskList = vo
      })
    }
  })
  return aitaskList
}

const getManaPlanTabs = () => {
  const permissionList: any = store.userApp.permissionList
  manaItemList.value = []

  manaPlanTabData.forEach((item: any) => {
    if (permissionList.find((vo: any) => vo === `workbench:manaPlan:${item.key}`)) {
      manaItemList.value.push(item.label)
    }
  })
}

// 根据方案类型 模板类型获取响应的列表
const getTemplateList = async (templateType, templateAffiliation) => {
  let data: any = []
  const res = await getTemplateDetailList({
    templateType: templateType,
    templateAffiliation: templateAffiliation,
    platformId: store.userStore.platformId
  })

  res.data.map((item: any) => {
    item.label = item.templateName
    item.value = item.id
  })
  data = res.data
  return data
}

// cron 表达式
// 每90天执行  0 0 0 */90 * *
// 每周一、周二、周四、周日的07:00:00, 21:00:00执行 0 7,21 * * 1,2,4,0

const isPushPlan = ref(false)
// 生成方案
const createPlan = () => {
  if (
    manaPlanForm.prescriptionData.length == 0 &&
    manaPlanForm.propagandaData.length == 0 &&
    manaPlanForm.followData.length == 0 &&
    manaPlanForm.monitorData.length == 0 &&
    manaPlanForm.medicationData.length == 0 &&
    manaPlanForm.visitData.length == 0 &&
    manaPlanForm.dietData.length == 0 &&
    manaPlanForm.sportData.length == 0
  ) {
    message.error('请至少填写一个方案后提交')
    return
  }

  if (manaPlanForm.dietData.length == 0) {
    message.error('请填写饮食方案后提交')
    return
  }

  if (manaPlanForm.sportData.length == 0) {
    message.error('请填写运动方案后提交')
    return
  }

  const data = holdpathData().data
  const dataEdit = holdpathData().dataEdit
  if (memberInfo.value.serviceState === 'DONE') {
    const newData = JSON.parse(JSON.stringify(data.list))
    const matchData = newData.map((item) => {
      if (item.templateType == '健康宣教') {
        item.content = JSON.stringify(item.contents)
      }

      return {
        manageId: item.manageId,
        managePathName: item.managePathName,
        templateId: item.templateId,
        cron: item.cron,
        cronCycle: item.cronCycle,
        cronDate: item.cronDate,
        cronTime: item.cronTime,
        templateType: item.templateType,
        templateName: item.templateName,
        id: item.id,
        content: item.content,
        templateAffiliation: item.templateAffiliation,
        creator: item.creator,
        taskCronType: item.taskCronType
      }
    })

    if (pathManageTemplateData === JSON.stringify(matchData)) {
      message.warning('当前方案未修改！')
      return
    }
  }

  const holdData = JSON.parse(JSON.stringify(data.list))
  holdData.forEach((item) => {
    if (item.templateType == '健康监测') {
      const content = JSON.parse(item.content)
      content.cronDate = item.cronDate
      content.cronTime = item.cronTime
      item.content = JSON.stringify(content)
    }

    if (
      item.templateType == '健康处方' ||
      item.templateType == '健康随访' ||
      item.templateType == '就诊提醒'
    ) {
      item.taskCronType = 2
    } else {
      item.taskCronType = 1
    }
  })

  const params = {
    hepMemberInfoVO: holdpathData().data.hepMemberInfoVO,
    list: holdData.map((item: any) => {
      return {
        content: item.content,
        cron: item.cron,
        cronCycle: item.cronCycle,
        cronDate: item.cronDate,
        cronTime: item.cronTime,
        id: item.id,
        manageId: item.manageId,
        managePathName: item.managePathName,
        taskCronType: item.taskCronType,
        templateAffiliation: item.templateAffiliation,
        templateId: item.templateId,
        templateName: item.templateName,
        templateType: item.templateType
      }
    })
  }

  holdManagePath(params).then((res) => {
    // 判断数据完整
    let isComplate = false
    try {
      dataEdit.list.forEach((item) => {
        switch (item.templateType) {
          case '健康处方':
            if (
              !item.content ||
              !item.cronCycle ||
              (!item.templateId && item.templateAffiliation != 'AI生成')
            ) {
              message.error('健康处方方案请填写完整')
              isComplate = true
              throw Error()
            }
            break
          case '健康宣教':
            if (!item.cronCycle || !item.content || !item.templateId) {
              message.error('健康宣教方案请填写完整')
              isComplate = true
              throw Error()
            }
            break
          case '健康随访':
            if (!item.cronCycle || !item.templateId) {
              message.error('健康随访方案请填写完整')
              isComplate = true
              throw Error()
            }
            break
          case '健康监测':
            if (
              !item.cronDates.length ||
              // !item.contents.content ||
              !item.cronTimes.length ||
              !item.cronTimes.join(',') ||
              !item.contents.sings ||
              !item.templateId
            ) {
              message.error('健康监测方案请填写完整')
              isComplate = true
              throw Error()
            }
            delete item.contents
            break
          case '用药提醒':
            if (
              !item.cronDates.length ||
              !item.content ||
              !item.cronTimes.length ||
              !item.cronTimes.join(',') ||
              !item.templateId
            ) {
              message.error('用药提醒方案请填写完整')
              isComplate = true
              throw Error()
            }
            break
          case '就诊提醒':
            if (!item.cronCycle || !item.content || !item.templateId) {
              message.error('就诊提醒方案请填写完整')
              isComplate = true
              throw Error()
            }

            if (
              dayjs(expiredTime.value).isBefore(
                dayjs(historyPathStartTime.value).add(item.cronCycle, 'day')
              )
            ) {
              message.error('就诊提醒方案提醒时间超过会员有效期，请重新选择')
              isComplate = true
              throw Error()
            }
            break
          case '饮食方案':
            if (!item.templateId && item.templateAffiliation != 'AI生成') {
              message.error('饮食方案请填写完整')
              isComplate = true
              throw Error()
            }

            if (item.content) {
              const content = JSON.parse(item.content)
              if (content) {
                content.seasons.forEach((vo) => {
                  vo.week.forEach((child) => {
                    if (child.itemContent.breakfast.food_items.length == 0) {
                      message.error(`饮食方案请填写完整`)
                      throw Error()
                    }

                    if (child.itemContent.lunch.food_items.length == 0) {
                      message.error(`饮食方案请填写完整`)
                      throw Error()
                    }

                    if (child.itemContent.dinner.food_items.length == 0) {
                      message.error(`饮食方案请填写完整`)
                      throw Error()
                    }
                  })
                })
              } else {
                message.error('饮食方案请填写完整')
                isComplate = true
                throw Error()
              }
            }
            break
          case '运动方案':
            if (!item.templateId && item.templateAffiliation != 'AI生成') {
              message.error('运动方案请填写完整')
              isComplate = true
              throw Error()
            }
            if (item.content) {
              const content = JSON.parse(item.content)

              content.week.forEach((vo) => {
                if (vo.sportType == '1') {
                  if (
                    !vo.aerobicSport.sportName ||
                    !vo.aerobicSport.total ||
                    vo.stretchSports.length == 0 ||
                    vo.warmupSports.length === 0
                  ) {
                    message.error(`运动方案请填写完整`)
                    isComplate = true
                    throw Error()
                  }
                }

                if (vo.sportType == '2') {
                  if (
                    !vo.groupNum ||
                    vo.resistanceSports.length == 0 ||
                    vo.stretchSports.length == 0 ||
                    vo.warmupSports.length === 0
                  ) {
                    message.error(`运动方案请填写完整`)
                    isComplate = true
                    throw Error()
                  }
                }
              })
            }
            break
          default:
            break
        }
      })
    } catch {
      return
    }
    if (isComplate) {
      //
    } else {
      isPushPlan.value = true
    }
  })
}

const pushPlanBtn = () => {
  isCreateHealthInfo.value = true
  generateManagePath({
    empi: memberInfo.value.empi,
    userId: memberInfo.value.userId,
    patName: memberInfo.value.patName,
    bizOrderNo: memberInfo.value.bizOrderNo,
    diseaseType: diseaseType.value
  })
    .then((res) => {
      isCreateHealthInfo.value = false
      message.success('推送成功')
      resetBack()
    })
    .catch((err) => {
      isCreateHealthInfo.value = false
    })
}

// 暂存
const staging = throttle(() => {
  if (Object.values(manaPlanForm).every((arr) => arr.length === 0)) {
    message.error('请至少填写一个方案后提交')
    return
  }

  const data = holdpathData().data
  const newData = data.list.map((item) => {
    const newItem = { ...item }

    if (newItem.templateType == '健康宣教') {
      newItem.content = JSON.stringify(newItem.contents)
    }

    return newItem
  })

  if (memberInfo.value.serviceState === 'DONE') {
    const matchData = newData.map((item) => {
      return {
        manageId: item.manageId,
        managePathName: item.managePathName,
        templateId: item.templateId,
        cron: item.cron,
        cronCycle: item.cronCycle,
        cronDate: item.cronDate,
        cronTime: item.cronTime,
        templateType: item.templateType,
        templateName: item.templateName,
        id: item.id,
        content: item.content,
        templateAffiliation: item.templateAffiliation,
        creator: item.creator,
        taskCronType: item.taskCronType
      }
    })

    if (pathManageTemplateData === JSON.stringify(matchData)) {
      message.warning('当前方案未修改！')
      return
    }
  }

  const holdData = _.cloneDeep(data.list)
  holdData.forEach((item: any) => {
    if (item.templateType === '健康监测') {
      const content = JSON.parse(item.content)
      content.cronDate = item.cronDate
      content.cronTime = item.cronTime
      item.content = JSON.stringify(content)
    } else if (item.templateType == '健康宣教') {
      item.content = JSON.stringify(item.contents)
    }

    item.taskCronType = ['健康处方', '健康随访', '就诊提醒'].includes(item.templateType) ? 2 : 1
  })

  const params = {
    hepMemberInfoVO: data.hepMemberInfoVO,
    list: holdData.map((item: any) => {
      return {
        content: item.content,
        cron: item.cron,
        cronCycle: item.cronCycle,
        cronDate: item.cronDate,
        cronTime: item.cronTime,
        id: item.id,
        manageId: item.manageId,
        managePathName: item.managePathName,
        taskCronType: item.taskCronType,
        templateAffiliation: item.templateAffiliation,
        templateId: item.templateId,
        templateName: item.templateName,
        templateType: item.templateType
      }
    })
  }

  holdManagePath(params)
    .then(() => {
      message.success('暂存成功')
      currentManaItemIndex.value = manaItemIndex.value
      manaItemIndex.value = -1
      return init(memberInfo.value, diseaseType.value)
    })
    .catch(() => {
      message.error('暂存失败')
    })
}, 500)

// 暂存数据
const holdpathData = () => {
  const monitorDatas = JSON.parse(JSON.stringify(manaPlanForm.monitorData))
  const monitorDatasEdit = JSON.parse(JSON.stringify(manaPlanForm.monitorData))

  monitorDatas.forEach((item) => {
    item.cronDate = item.cronDates.join(',')
    item.cronTime = item.cronTimes.join(',')
    item.content = JSON.stringify({
      ...item.contents,
      cronDate: item.cronDate,
      cronTime: item.cronTime
    })
    delete item.cronDates
    delete item.cronTimes
    delete item.contents
  })

  const medicationDatas = JSON.parse(JSON.stringify(manaPlanForm.medicationData))
  const medicationDatasEdit = JSON.parse(JSON.stringify(manaPlanForm.medicationData))
  medicationDatas.forEach((item) => {
    item.cronDate = item.cronDates.join(',')
    item.cronTime = item.cronTimes.join(',')
    delete item.cronDates
    delete item.cronTimes
  })

  // 饮食
  const dietDatas = JSON.parse(JSON.stringify(manaPlanForm.dietData))
    .splice(0, 2)
    .filter((vo) => vo.pushStatus != '未推送' || vo.templateAffiliation != 'AI生成')
  // const dietDatasEdit = JSON.parse(JSON.stringify(manaPlanForm.dietData))
  dietDatas.forEach((item) => {
    item.content = JSON.stringify(item.content)
    item.cronCycle = 1
  })
  // 运动
  const sportDatas = JSON.parse(JSON.stringify(manaPlanForm.sportData))
    .splice(0, 2)
    .filter((vo) => vo.pushStatus != '未推送' || vo.templateAffiliation != 'AI生成')
  // const sportDatasEdit = JSON.parse(JSON.stringify(manaPlanForm.sportData))
  sportDatas.forEach((item) => {
    const week = item.content.week
    week.forEach((vo) => {
      if (vo.sportType == '1') {
        vo.resistanceSports = []
        vo.groupNum = undefined
      } else if (vo.sportType == '2') {
        vo.aerobicSport = {
          sportId: undefined,
          sportName: undefined,
          total: undefined
        }
      } else if (vo.sportType == '3') {
        Object.assign(vo, {
          warmupSports: [],
          aerobicSport: {
            sportId: undefined,
            sportName: undefined,
            total: undefined
          },
          stretchSports: [],
          resistanceSports: [],
          groupNum: undefined
        })
      }
    })
    item.content = JSON.stringify(item.content)
    item.cronCycle = 1
  })

  const data = {
    hepMemberInfoVO: memberInfo.value,
    list: [
      ...JSON.parse(JSON.stringify(manaPlanForm.prescriptionData)),
      ...JSON.parse(JSON.stringify(dietDatas)),
      ...JSON.parse(JSON.stringify(sportDatas)),
      ...JSON.parse(JSON.stringify(manaPlanForm.propagandaData)),
      ...JSON.parse(JSON.stringify(manaPlanForm.followData)),
      ...monitorDatas,
      ...medicationDatas,
      ...JSON.parse(JSON.stringify(manaPlanForm.visitData))
    ]
  }
  const dataEdit = {
    hepMemberInfoVO: memberInfo.value,
    list: [
      ...JSON.parse(JSON.stringify(manaPlanForm.prescriptionData)),
      ...JSON.parse(JSON.stringify(dietDatas)),
      ...JSON.parse(JSON.stringify(sportDatas)),
      ...JSON.parse(JSON.stringify(manaPlanForm.propagandaData)),
      ...JSON.parse(JSON.stringify(manaPlanForm.followData)),
      ...monitorDatasEdit,
      ...medicationDatasEdit,
      ...JSON.parse(JSON.stringify(manaPlanForm.visitData))
    ]
  }

  return {
    data: data,
    dataEdit: dataEdit
  }
}

// 历史执行
const planPushPlanHisRef = ref()
const planPushPlanHisHandle = () => {
  planPushPlanHisRef.value.init(memberInfo.value, true)
}

const goIM = () => {
  if (diseaseType.value == 'checkAfter') {
    router.push({
      path: '/healthManaConsultTwo/index'
    })
  } else {
    router.push({
      path: '/weightLossServicePack/index'
    })
  }
}

const resetBack = () => {
  if (memberRouterData.value.back) {
    if (memberRouterData.value.back === '1') {
      router.push({
        path: '/warningCenter/index',
        query: {
          back: memberRouterData.value.back,
          backtype: memberRouterData.value.backtype
        }
      })
    }
  } else {
    router.replace({ query: {} })
    emit('close')
  }
}

const goBack = () => {
  showDetail.value = false
}

const goPage = (data) => {
  showDetail.value = true
  nextTick(() => {
    patientInfoRef.value.initRouterInfo(data)
  })
}

// 刷新数据
const refreshData = () => {
  init(memberInfo.value, diseaseType.value)
}

defineExpose({
  init
})
</script>
<style lang="less" scoped>
.box-main {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  padding: 0 !important;
  overflow: hidden !important;

  .topHeaderCard {
    display: flex;
    align-items: center;
    width: 100%;
    height: 48px;
    padding-left: 24px;
    background-color: #fff;

    ::v-deep(.ant-tabs-nav) {
      margin: 0;
    }

    ::v-deep(.ant-tabs-nav-wrap) {
      height: 48px;
      padding: 0 20px;
      padding-top: 2px;
    }
  }

  .box-main-content {
    width: 100%;
    height: calc(100% - 50px);
    padding: 0;
    overflow: hidden;

    .page-content {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 16px 16px 0;
      border-radius: 8px;
    }
  }
}

.info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background-color: #f7f8fa;
  border-radius: 8px;

  .info-left {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
  }
}

.info-content {
  height: calc(100% - 120px);
  background-color: #fff;

  .empty-box {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
}

.patient-info {
  display: flex;
  align-items: center;

  img {
    width: 48px;
    height: 48px;
    margin-right: 8px;
    border-radius: 50%;
  }
}

.patient-info,
.member-info,
.visit-info {
  color: #4e5969;
}

.patient-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.mana-plan-box {
  display: flex;
  flex-direction: column;
  height: calc(100% - 6px);
  padding: 0 16px 6px 20px;
  padding-bottom: 8px;
}

.mana-plan-title {
  display: flex;
  align-items: center;
  height: 45px;
  padding: 0 0 8px;
  font-size: 18px;

  span {
    font-weight: 600;
  }
}

.mana-plan-content {
  display: flex;
  flex-direction: column;
  height: calc(100% - 50px);

  .mana-plan-content-info {
    height: 100%;
    overflow: hidden;
  }

  .mana-plan-item {
    .mana-item-name {
      display: inline-block;
      width: 130px;
      padding: 5px 10px;
      margin: 0 8px 4px 0;
      text-align: center;
      cursor: pointer;
      border: 1px solid #e5e5e5;
      border-radius: 6px;
    }

    .mana-item-name-active {
      background-color: #c4c4c4;
    }

    ::v-deep(.ant-tabs-nav) {
      margin-bottom: 8px;
    }
  }

  .mana-plan-main {
    height: calc(100% - 58px);
    padding: 0 5px 0 0;
    overflow: hidden auto;
  }
}

.mana-plan-item-info {
  padding: 16px 0;
  // background-color: #f7f8fa;
  margin-bottom: 16px;
  border: 1px solid #e5e5e5;
}

.mana-plan-footer {
  margin-top: 8px;
  text-align: right;
}

.mana-plan-form .ant-form-item {
  padding-left: 24px;
  margin-bottom: 12px;
}

.mana-plan-form .sprot-form .ant-form-item {
  margin-bottom: 18px;
}

.text-icon {
  display: inline-block;
  width: 3px;
  height: 16px;
  margin-right: 8px;
  line-height: 32px;
  background: #165dff;
}

.template-col {
  padding: 6px 20px;
  cursor: pointer;
  border: 1px solid #e5e5e5;
  border-radius: 2px;
}

.template-col.template-col-active {
  color: #fff;
  background-color: #165dff;
}

.diet-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.diet-type {
  display: inline-block;
  width: 60px;
  margin-right: 10px;
  text-align: right;
}
</style>
